package com.kmxd.ams.app.use;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kmxd.ams.client.use.IUsePushUserSvc;
import com.kmxd.ams.client.use.dto.UsePushUserAddDTO;
import com.kmxd.ams.client.use.dto.UsePushUserEditDTO;
import com.kmxd.ams.client.use.dto.UsePushUserQueryDTO;
import com.kmxd.ams.client.use.vo.UsePushUserListVO;
import com.kmxd.ams.client.use.vo.UsePushUserVO;
import com.kmxd.ams.core.common.query.QueryGen;
import com.kmxd.ams.core.util.IdUtil;
import com.kmxd.ams.infra.use.entity.UsePushUser;
import com.kmxd.ams.infra.use.mapper.UsePushUserMapper;
import java.util.List;
import java.util.Set;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 推送人员表 服务实现类
 *
 * @author nickbi
 * @since 2023-01-11
 */
@Service
@AllArgsConstructor
public class UsePushUserSvcImpl extends ServiceImpl<UsePushUserMapper, UsePushUser>
    implements IUsePushUserSvc {

  private UsePushUserMapper usePushUserMapper;

  @Override
  public Page<UsePushUserListVO> selectPage(Page reqPage, UsePushUserQueryDTO req) {
    LambdaQueryWrapper<UsePushUser> queryWrapper =
        QueryGen.init(new QueryWrapper<UsePushUser>(), req).lambda();
    Page<UsePushUser> page = usePushUserMapper.selectPage(reqPage, queryWrapper);
    Page<UsePushUserListVO> voPage = BeanUtil.copyProperties(page, Page.class);
    voPage.setRecords(BeanUtil.copyToList(page.getRecords(), UsePushUserListVO.class));
    return voPage;
  }

  @Override
  public List<UsePushUserListVO> selectList(UsePushUserQueryDTO req) {
    LambdaQueryWrapper<UsePushUser> queryWrapper =
        QueryGen.init(new QueryWrapper<UsePushUser>(), req).lambda();
    List<UsePushUser> list = usePushUserMapper.selectList(queryWrapper);
    return BeanUtil.copyToList(list, UsePushUserListVO.class);
  }

  @Override
  @Transactional(rollbackFor = Exception.class)
  public void add(UsePushUserAddDTO req) {
    UsePushUser entity = BeanUtil.copyProperties(req, UsePushUser.class);
    usePushUserMapper.insert(entity);
  }

  @Override
  @Transactional(rollbackFor = Exception.class)
  public void edit(UsePushUserEditDTO req) {
    UsePushUser entity = BeanUtil.copyProperties(req, UsePushUser.class);
    usePushUserMapper.updateById(entity);
  }

  @Override
  @Transactional(rollbackFor = Exception.class)
  public void remove(String ids) {
    Set<Long> idList = IdUtil.split(ids);
    this.baseMapper.deleteBatchIds(idList);
  }

  @Override
  public UsePushUserVO view(Long id) {
    UsePushUser entity = usePushUserMapper.selectById(id);
    return BeanUtil.copyProperties(entity, UsePushUserVO.class);
  }
}
